<template>
	<view class="container">
		<view class="title">
			{{detail.title}}
		</view>
		<view class="text">
			<rich-text :nodes="detail.content"></rich-text>
		</view>
		<view class="date">
			<span>{{detail.create_time_text || formatTime(detail.create_time)}}</span>
			<span>{{detail.user_name || ''}}</span>
		</view>
	</view>
</template>


<script>
	import {
		noticeInfo
	} from '@/api/part2.js'
	export default {
		data() {
			return {
				detail:{
					title: '',
					content: '',
					date:'',
					user:''
				}
			};
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
				title: options.title
			});
			this.getDetail(options.id)
		},
		methods: {
			getDetail(id){
				noticeInfo({id}).then(res=>{
					this.detail = res.data.data
				})
			},
			formatTime(timestamp, format = 'YYYY-MM-DD') {
			  if (!timestamp) return '';
			  
			  const date = new Date(timestamp * 1000);
			  const config = {
			    YYYY: date.getFullYear(),
			    MM: String(date.getMonth() + 1).padStart(2, '0'),
			    DD: String(date.getDate()).padStart(2, '0'),
			    HH: String(date.getHours()).padStart(2, '0'),
			    mm: String(date.getMinutes()).padStart(2, '0'),
			    ss: String(date.getSeconds()).padStart(2, '0')
			  };
			  
			  return format.replace(/(YYYY|MM|DD|HH|mm|ss)/g, match => config[match]);
			},
		},
	};
</script>

<style lang="less" scoped>
	.container {
		padding: 0 32rpx;
		padding-bottom: 150rpx;
		margin-bottom: constant(safe-area-inset-bottom);
		margin-bottom: env(safe-area-inset-bottom);
		background: #F5F6FA;
		min-height: 100vh;
		.title {
			font-size: 50rpx;
			text-align: center;
		}
		.text {
			font-size: 40rpx;
			padding: 80rpx 0;
		}
		.date {
			display: flex;
			gap: 10rpx;
			justify-content: flex-end;
			margin-top: 20rpx;
		}
	}
</style>